#ifndef MDTX_USE_RCPPARMADILLO
#define MDTX_USE_RCPPARMADILLO
#endif

#include <RcppArmadillo.h>
using namespace Rcpp;

#include "mdtx-online/indicator/indicator_type_s4.h"
using namespace mdtx::online;

#include "indi_common.h"

using rollmoment_cu_ = indi4<indicator::rollmoment_cu>;

//' Cumulative central moments
//'
//' @param x Numeric vector
//' @return List of m, m2, m3, m4
//' @export
// [[Rcpp::export(rng = false)]]
List rollmoment_cu(NumericVector x)
{
    auto c = rollmoment_cu_::create_t();
    auto ans = rollmoment_cu_::run_t(c, x);
    ans.names() = CharacterVector::create("m", "m2", "m3", "m4");
    return ans;
}

// [[Rcpp::export(rng = false)]]
SEXP rollmoment_cu_new()
{
    return rollmoment_cu_::create();
}

// [[Rcpp::export(rng = false)]]
List rollmoment_cu_run(SEXP ptr, NumericVector x)
{
    auto ans = rollmoment_cu_::run(ptr, x);
    ans.names() = CharacterVector::create("m", "m2", "m3", "m4");
    return ans;
}

using rollmoment_ = indi4<indicator::rollmoment>;

//' Rolling central moments
//'
//' @param x Numeric vector
//' @param period Period of rolling window
//' @return List of M, M2, M3, M4
//' @export
// [[Rcpp::export(rng = false)]]
List rollmoment(NumericVector x, int period)
{
    auto c = rollmoment_::create_t(period);
    auto ans = rollmoment_::run_t(c, x);
    ans.names() = CharacterVector::create("m", "m2", "m3", "m4");
    return ans;
}

// [[Rcpp::export(rng = false)]]
SEXP rollmoment_new(int period)
{
    return rollmoment_::create(period);
}

// [[Rcpp::export(rng = false)]]
List rollmoment_run(SEXP ptr, NumericVector x)
{
    auto ans = rollmoment_::run(ptr, x);
    ans.names() = CharacterVector::create("m", "m2", "m3", "m4");
    return ans;
}
